package com.preskool.service.impl;

import com.preskool.mapper.ExpensesMapper;
import com.preskool.po.Expenses;
import com.preskool.service.ExpensesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *花费页面
 * @Author swj
 * @Date 2021/1/7
 * @version1.0
 */
@Service
public class ExpensesServiceImpl implements ExpensesService {
    //注入ExpensesMapper接口
    @Autowired(required = false)
    private ExpensesMapper expensesMapper;

    /**
     * 查询全部数据,并进行分页
     * @return
     */
    @Override
    public List<Expenses> findAllPage(Integer currentPage,Integer pageSize) {
        List<Expenses> expenses = expensesMapper.selectAllPaging(currentPage,pageSize);
        return expenses;
    }

    /**
     * 通过id查询单条数据
     * @param extid
     * @return
     */
    @Override
    public Expenses findOne(Integer extid) {
        Expenses expense = expensesMapper.selectByPrimaryKey(extid);
        return expense;
    }

    /**
     * 更新数据,可以更新部分字段
     * @param expenses
     * @return
     */
    @Override
    public int updateExp(Expenses expenses) {
        int update = expensesMapper.updateByPrimaryKeySelective(expenses);
        return update;
    }

    /**
     * 增加费用
     * @param expenses
     * @return
     */
    @Override
    public int addExpenses(Expenses expenses) {
        int add = expensesMapper.insertSelective(expenses);
        return add;
    }

    /**
     * 通过id删除数据
     * @param exid
     * @return
     */
    @Override
    public int delExpenses(Integer exid) {
        int delete = expensesMapper.deleteByPrimaryKey(exid);
        return delete;
    }
}
